﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Skyhook.Core;
using Skyhook.Resources;

namespace Skyhook.Logic
{
    static class TankVisualStates
    {
        public const int Unknown = -1;
        public const int Normal = 0;
        public const int Damaged = 1;
        public const int Destroyed = 2;
    }
    class TankVisualController : VisualController
    {
        int pHullDirection = 0;
        int pTurretDirection = 0;
        int pState = 0;

        LoopInteger HullAngle = null;
        LoopInteger TurretAngle = null;

        public TankVisualController() : base()
        {
            
        }

        public void SetAngleControllers(LoopInteger hullangle, LoopInteger turretangle)
        {
            if (hullangle == null || turretangle == null)
            {
                throw new NullReferenceException();
            }

            HullAngle = hullangle;
            TurretAngle = turretangle;

            HullAngle.OnChange += OnHullAngleChange;
            TurretAngle.OnChange += OnTurretAngleChange;
        }

        void OnHullAngleChange(int angle)
        {
            SetGroupsCurrentEntity(angle, 0, 1, 2, 3);
        }

        void OnTurretAngleChange(int angle)
        {
            SetGroupsCurrentEntity(angle, 4, 5, 6);
        }

        public int State
        {
            get
            {
                return pState;
            }
            set
            {
                switch (value)
                {
                    case TankVisualStates.Normal:
                        ShowGroups(0,3,4,6);
                        break;
                    case TankVisualStates.Damaged:
                        ShowGroups(1, 3, 4, 6);
                        break;
                    case TankVisualStates.Destroyed:
                        ShowGroups(2, 3, 5, 6);
                        break;
                }
                pState = value;
            }
        }      
    }
}
